package cn.iocoder.yudao.module.system.api.partner;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.system.api.partner.dto.PartnerReqDTO;
import cn.iocoder.yudao.module.system.api.partner.dto.PartnerRespDTO;
import cn.iocoder.yudao.module.system.api.partner.dto.PartnerSendReqDTO;
import cn.iocoder.yudao.module.system.controller.admin.partner.vo.PartnerPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.partner.PartnerDO;
import cn.iocoder.yudao.module.system.service.partner.PartnerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PartnerApiImpl implements PartnerApi {

    @Resource
    private PartnerService partnerService;

    @Override
    public PartnerRespDTO getEnabledPartnerByPhone(String phone) {
        PartnerPageReqVO reqVO = new PartnerPageReqVO();
        reqVO.setPhone(phone);
        reqVO.setStatus(Boolean.TRUE);
        List<PartnerDO> partnerDOList = partnerService.getList(reqVO);
        if (CollUtil.isNotEmpty(partnerDOList)) {
            return BeanUtil.copyProperties(partnerDOList.get(0), PartnerRespDTO.class);
        }
        return null;
    }

    @Override
    public List<PartnerRespDTO> getListApi(PartnerReqDTO reqVO) {
        List<PartnerDO> partnerDOList = partnerService.getListApi(reqVO);
        if (CollUtil.isNotEmpty(partnerDOList)) {
            return BeanUtil.copyToList(partnerDOList, PartnerRespDTO.class);
        }
        return null;
    }



    @Override
    public List<PartnerRespDTO> getListByIds(List<Long> partnerIds) {
        List<PartnerDO> partnerDOList = partnerService.getListByIds(partnerIds);
        if (CollUtil.isNotEmpty(partnerDOList)) {
            return BeanUtil.copyToList(partnerDOList, PartnerRespDTO.class);
        }
        return null;
    }

    @Override
    public Long updatePartnerAmount(List<PartnerSendReqDTO> reqDTOs) {
        reqDTOs.forEach(reqDTO -> {
            partnerService.updatePartnerAmount(reqDTO);
        });
        return Long.valueOf(reqDTOs.size());
    }
}